package m.store.model;

import m.base.model.StoreInfo;
import m.common.model.*;
import m.common.model.type.FieldType;
import m.common.model.util.ModelQueryList;
import m.common.model.util.QueryCondition;
import m.system.cache.FlushCacheList;

import java.util.List;
import java.util.stream.Collectors;

@TableMeta(name="ts_store_type",description="商户商品分类")
public class StoreType extends Model implements DictionaryModel,MigrationModel {
    @Override
    public List<String> migrationOidList(String storeOid) throws Exception {
        return ModelQueryList.getModelList(this.getClass(),new String[]{"oid"},null,
                        QueryCondition.eq("store.oid",storeOid))
                .stream().map(Model::getOid).collect(Collectors.toList());
    }
    @LinkTableMeta(name="store_oid",table= StoreInfo.class,description="所属商户")
    private StoreInfo store;
    @FieldMeta(name="name",type= FieldType.STRING,length=50,description="名称")
    private String name;
    @FieldMeta(name="sort",type=FieldType.INT,description="排序")
    private Integer sort;

    public StoreInfo getStore() {
        return store;
    }

    public void setStore(StoreInfo store) {
        this.store = store;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getSort() {
        return sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }

    @Override
    public String getDictValue() {
        return this.getOid();
    }

    @Override
    public String getDictName() {
        return getName();
    }

    @Override
    public String getDictParentOid() {
        return "";
    }

    @Override
    public String getDictStatus() {
        return "Y";
    }

    @Override
    public List<StoreType> getCacheList(String storeOid) throws Exception {
        return ModelQueryList.getModelList(StoreType.class,new String[]{"oid","name","sort"},null, QueryCondition.eq("store.oid",storeOid));
    }
}
